home *** CD-ROM | disk | FTP | other *** search
- Path: lrz-muenchen.de!news
- From: watzka@stat.uni-muenchen.de (Kurt Watzka)
- Newsgroups: comp.lang.c
- Subject: Re: Standard question - pointer initialization
- Date: 13 Mar 1996 00:40:26 GMT
- Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
- Distribution: world
- Message-ID: <4i55hq$sc1@sparcserver.lrz-muenchen.de>
- References: <4hk9un$906@hammer.msfc.nasa.gov> <4i52bk$5el@s02.pavilion.co.uk>
- NNTP-Posting-Host: sun2.lrz-muenchen.de
-
- AJRobb@pavilion.co.uk (Andy J Robb) writes:
-
- >Brian.Day@msfc.nasa.gov (Brian Day) wrote:
-
- >>Doesn't the standard say something about some pointers
- >>being automatically initialized to NULL, or something like that?
-
- >Off the top of my head, the only time pointers are initialized to NULL
- >is if they are global or static.
-
- >The use of calloc() allows a list of NULL initialized pointers to be
- >generated.
-
- Yes it does:
-
- int i;
- foo *p = calloc(N, sizeof *p);
- if (p)
- for (i = 0; i < N; i++)
- p[i] = NULL;
-
- However, this statement is somehow misleading because it could
- be understood to mean something like "if you allocate a vector
- of pointers with calloc(), all pointers will be initialized
- to NULL", which is not true. A NULL pointer need not have all
- bits set to zero, and this is what calloc() does with the memory
- it allocates.
-
- Kurt
- --
- | Kurt Watzka Phone : +49-89-2180-6254
- | watzka@stat.uni-muenchen.de
- | ua302aa@sunmail.lrz-muenchen.de
-
-